<?php

class Message_model extends MY_Model
{
    protected $_table = 'chatmessage';   
    protected $primary_key = 'messageid';   
    
    function post_message_($data)
    {
    	return $this->insert($data, TRUE);
    }
    function get_messages($threadid, $meth, $isuser, $lastid, $kind_for_agent)
    {
    	$this->db->select("messageid,ikind,unix_timestamp(dtmcreated) as created,tname,tmessage");
    	$this->db->where('threadid', $threadid);
    	$this->db->where('messageid > ', $lastid);
    	if($isuser){
	    	$this->db->where('ikind <>', $kind_for_agent);
    	}
    	return $this->db->get($this->_table)->result_array();
    }
    function get_message_count_onclose($threadid)
    {
    	return $this->count_by(array('threadid' => $threadid, 'ikind' => 1));
    }
    function get_message($messageid)
    {
    	return $this->get_array($messageid);
    }
}
